package com.beiding.service;

import com.beiding.dao.ResourceOperations;
import com.beiding.exception.AuthenticationException;

import java.util.Optional;

public interface ResourceService<T> {

    //检查资源持有者
    default void checkHolder(String id, String holderId) {

        if (!resourceOperations().checkHolder(id, holderId)) {
            throw new AuthenticationException("无权操作!");
        }

    }

    default  T get(String id, String... limitFiled)
    {
        Optional<T> optional = resourceOperations().findByIdLimitFields(id,limitFiled);
        return optional.orElse(null);
    }

    ResourceOperations<T> resourceOperations();
}
